package com.example.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.security.model.Userinfo;
import com.example.security.service.UserinfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class MyUserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserinfoService userinfoService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //1.从数据库加载用户信息
        System.out.println("进入loadUserByUsername，参数username为：{}"+username);
//        Userinfo userinfo = userinfoService.getOne(new QueryWrapper<Userinfo>().lambda().
//                eq(Userinfo::getUsername, username));
        //2.从数据库加载该用户的权限信息
        Userinfo userinfo = userinfoService.queryUserListAndRelationRole(username);

        return userinfo;
    }
}
